/**
 * @(#) Component.java
 */

package cn.edu.sjtu.se.dslab.component;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import cn.edu.sjtu.se.dslab.auth.User;

@Entity
@Table(name = "component")
@Inheritance(strategy = InheritanceType.JOINED)
public class Component implements Serializable {
	private static final long serialVersionUID = 1L;
	private long id;
	
	private String name;
	
	private User owner;

	private String type;

	private String version;

	private Date lastModified;

	private Date createTime;

	private String description;

	private String uri;

	private boolean deleted;
	
	
	@Column(name = "deleted", nullable = true)
	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Component() {
		super();
		deleted = false;
	}

	public Component(User owner, String type, String version,
			Date lastModified, Date createTime, String description) {
		super();
		this.owner = owner;
		this.type = type;
		this.version = version;
		this.lastModified = lastModified;
		this.createTime = createTime;
		this.description = description;
		deleted = false;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH})
	@JoinColumn(name = "owner_id")
	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	@Column(name = "uri", nullable = true, length = 255)
	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	@Column(name = "type", nullable = true, length = 255)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "version", nullable = true, length = 255)
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	
	@Column(name = "name", nullable = true, length = 255)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, insertable = true, name = "last_modified")
	public Date getLastModified() {
		return lastModified;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, insertable = true, updatable = false, name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "description", nullable = true, length = 255)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}
